#include<bits/stdc++.h>
#define int __int128
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
int n,m;
int a[25];
int fac[25];
bool vis[25];
void OUT(int len,int ops){
	if(ops)cout<<"----\n";
	for(int i=1;i<=len;i++){
		int x=(m+fac[len-i]-1)/fac[len-i];
		int now=x;
		if(ops==0){
			for(int j=1;j<=n;j++){
				if(vis[j])continue;
				now--;
				if(now==0){write(j),putch(' ');break;}	
			}
		}else{
			for(int j=19;j>=0;j--){
				if(vis[j])continue;
				now--;
				if(now==0){write(n-j),putch(' ');break;}
			}
		}
		m-=(x-1)*fac[len-i];
	}
}
void dfs(int x,int sum){
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		if(sum+i>=n){
			if(m<=fac[n-x]){
				vis[i]=1;
				for(int i=1;i<=x;i++)write(a[i]),putch(' ');
				OUT(n-x,0);
				flush();
				exit(0);
			}else m-=fac[n-x];
		}else dfs(x+1,sum+i);
	}
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=24;i++)fac[i]=1LL*i*fac[i-1];
	read(n,m);
	if(n<=24){
		for(int i=3;i<=n;i++){
			a[1]=i;
			vis[i]=1;
			dfs(2,i);
			vis[i]=0;
		}
	}else{
		write(3),putch(' '),write(1),putch(' '),write(2),putch(' ');
		for(int i=4;i<=n-20;i++)write(i),putch(' ');
		OUT(20,1);
	}
	flush();
	return 0;
}

